﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace MercuryFE
{
    public abstract class BaseConverter : MarkupExtension
{
    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return this;
    }
}

    [ValueConversion(typeof(object), typeof(int))]    
    public class FontSizeConverter : BaseConverter, IValueConverter    
    {        
        public object Convert(object value, Type targetType, object parameter,
                          System.Globalization.CultureInfo culture)        
        {



            double height = double.Parse(value.ToString());
            double desiredRows = double.Parse(parameter.ToString());
            //TextBlock tb = (TextBlock)value;

            //UIElement test = (UIElement)tb.Parent;

           // Window win =  ClientLib.getWindowByName("Simple");


            int fontSize = (int)Math.Truncate(height / desiredRows);

            //if(value.GetType() == 
            ////int fontSize = (int)(0.65*mainGrid.RowDefinitions[0].ActualHeight);


            //string format = parameter as string;
            //if (!string.IsNullOrEmpty(format))
            //{                
            //     return string.Format(culture, format, value);
            //}
            //else              
            //    return value.ToString();

            return fontSize;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter,
                        System.Globalization.CultureInfo culture)
        {
            return null; 
        }            
    }

}
